/*
 * Copyright (C) 2013 Daniel Wasilew <daniel.wasilew@codeminer.org>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package org.codeminer.parts.database.derby;

import java.util.List;
import org.codeminer.database.DatabaseException;
import org.codeminer.parts.database.AlbumConnector;
import org.codeminer.parts.database.dao.AlbumDAO;
import org.codeminer.parts.library.Album;
import org.codeminer.parts.library.Artist;
import org.codeminer.parts.library.Song;

/**
 *
 * @author Daniel Wasilew <daniel.wasilew@codeminer.org>
 */
public class DerbyAlbumStorageConnector extends DerbyStorageConnector implements AlbumConnector {

    @Override
    public Album storeAlbum(Album album) throws DatabaseException {
        long id = AlbumDAO.store(album, getConnection());
        album.setOid(id);
        return album;
    }

    @Override
    public boolean updateAlbum(Album album) throws DatabaseException {
        return AlbumDAO.update(album, getConnection());
    }

    @Override
    public boolean deleteAlbum(Album album) throws DatabaseException {
        return AlbumDAO.delete(album, getConnection());
    }

    @Override
    public void addSongToAlbum(Song song, Album album) throws DatabaseException {
        AlbumDAO.addSongToAlbum(song, album, getConnection());
    }

    @Override
    public List<Album> getAlbums(Album searchCriteria) throws DatabaseException {
        return AlbumDAO.get(searchCriteria, getConnection());
    }

    @Override
    public List<Album> getAlbums(Artist searchCriteria) throws DatabaseException {
        return AlbumDAO.get(searchCriteria, getConnection());
    }

    @Override
    public List<Album> getAlbums() throws DatabaseException {
        return AlbumDAO.get((Album) null, getConnection());
    }

    @Override
    public Class getAccessorDescription() {
        return AlbumConnector.class;
    }
}
